package com.hospital.servlet;

import java.io.IOException;

import java.text.SimpleDateFormat;
import java.util.*;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hospital.util.DbUtil;
@WebServlet("/manage/PatientMoneyServlet")
public class PatientMoneyServlet extends HttpServlet {
	protected void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
		String method = request.getParameter("method");
		String addmoneyR = null;
		if ("modify".equals(method)) {
			String account = request.getParameter("account").trim();
			String addmoney = request.getParameter("addmoney").trim();
			int money = Integer.parseInt(addmoney);
			addmoneyR = addmoney;
			String sql = "update t_patient_info set money = money + " + money +  " where account = '" + account + "'";
			DbUtil.add_modify(sql);
			String sqlmoney = "insert into t_patient_money(account, addmoney, addtime) values('"
					+ account + "', '" + addmoney + "','" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime()) + "')";
			DbUtil.add_modify(sqlmoney);
		}
		request.setAttribute("rs", "已经为病人充值成功充值" + addmoneyR + "人民币！");
		request.getRequestDispatcher("/manage/patientmoney_info_modify.jsp").forward(request, response);
	}
}
